<template>
	<view class="bg-view-packbox relative" @click="$emit('click')" :style="{ 'background-image': `url(${isNetworkImg(src)})`, 'background-size': `${backgroundSize}` }">
		<image class="bg" :src="src" v-if="!isNetworkImg(src)"></image>
		<view class="relative">
			<slot></slot>
		</view>
	</view>
</template>

<script>
	export default {
		name: 'comBgView',
		props: {
			src: {
				type: String,
				default: () => ''
			},
			backgroundSize: {
				type: String,
				default: () => '100% 100%'
			}
		},
		data() {
			return {};
		},
		methods: {
			isNetworkImg(src) {
				// 网络图片用background背景样式,本地图片用image标签
				if (src.includes('http://') || src.includes('https://')) {
					return src;
				} else {
					return '';
				}
			}
		}
	};
</script>

<style scoped>
	.bg-view-packbox {
		background-position: center center;
		background-size: 100% 100%;
	}
</style>
